/**
 * Filename: ChooseAlbumAdapter.java
 * @author  Firefly
 * @contact postfirefly@163.com
 * @time    2016/4/22 7:45
 */
package com.github.postsanf.yinian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.github.postsanf.yinian.bean.YNImageFloder;
import com.github.postsanf.yinian.utils.LocalViewHolder;

import java.util.List;

public abstract class ChooseAlbumAdapter<T> extends BaseAdapter
{
	protected LayoutInflater mInflater;
	protected Context mContext;
	protected List<T> mDatas;
	protected final int mItemLayoutId;

	public ChooseAlbumAdapter(Context context, List<T> mDatas, int itemLayoutId)
	{
		this.mContext = context;
		this.mInflater = LayoutInflater.from(mContext);
		this.mDatas = mDatas;
		this.mItemLayoutId = itemLayoutId;
	}

	// 第一个为新建相册  所以总数+1
	@Override
	public int getCount()
	{
		return mDatas.size();
	}

	@Override
	public T getItem(int position)
	{
		return mDatas.get(position);
	}

	@Override
	public long getItemId(int position)
	{
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		final LocalViewHolder viewHolder = getViewHolder(position, convertView,
				parent);

//		if (getItem(0) instanceof YNImageFloder)
//		{
//			convert(viewHolder, getItem(position),false);
//			return viewHolder.getConvertView();
//		}
//
//		if (position == 0)
//		{
//			convert(viewHolder, getItem(position) ,true);
//		}
//		else
//		{
//			convert(viewHolder, getItem(position-1),false);
//		}

		convert(viewHolder, getItem(position),false);

		return viewHolder.getConvertView();

	}

	public abstract void convert(LocalViewHolder helper, T item ,Boolean isFirst);

	private LocalViewHolder getViewHolder(int position, View convertView,
									 ViewGroup parent)
	{
		return LocalViewHolder.get(mContext, convertView, parent, mItemLayoutId,
				position);
	}

}
